/**
 * 最长的严格递增或递减子数组
 *
 * @USER: Administrator
 * @DATE: 2024/10/5 下午2:20
 * @VERSION: 1.0.0
 */
public class LC3105 {
    public static void main(String[] args) {

    }

    public int longestMonotonicSubarray(int[] nums) {
        int maxAsc = 1, maxDesc = 1;
        int countAsc = 1, countDesc = 1;
        // 最长递增子数组
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] > nums[i - 1]) {
                countAsc++;
                if (countAsc > maxAsc) {
                    maxAsc = countAsc;
                }
            }else {
                countAsc = 1;
            }

            if (nums[i] < nums[i - 1]) {
                countDesc++;
                if (countDesc > maxDesc) {
                    maxDesc = countDesc;
                }
            }else {
                countDesc = 1;
            }

        }
        return Math.max(maxAsc, maxDesc);
    }

}
